package cn.dd.crmweb.modules.sys.controller;

import cn.dd.crmweb.common.Result;
import cn.dd.crmweb.modules.sys.entity.Menu;
import cn.dd.crmweb.modules.sys.entity.Role;
import cn.dd.crmweb.modules.sys.service.IMenuService;
import cn.dd.crmweb.modules.sys.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/sys/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    //查询所有
    @GetMapping("/list")
    public Result findAll(@RequestParam(defaultValue = "") String name){
        return  Result.success(menuService.findMenus(name));
    }



    //新增或修改
    @PostMapping("/add")
    public boolean save(@RequestBody Menu menu){
        return  menuService.saveOrUpdate(menu);
    }

    @DeleteMapping("{id}/delete")
    public boolean delete(@PathVariable("id") String id ) {
        return  menuService.removeById(id);
    }

    @DeleteMapping("batch/delete")
    public boolean deleteBatch(@RequestBody List<String> ids){
        return  menuService.removeByIds(ids);
    }
}
